/**
 * 游戏世界，包含UI
 * @author zhouzhanglin
 */
GameWorld = function()
{
	Sprite.call( this ) ;
	
	this._back = new Bitmap( ResManager.getInstance().getBmdByName("back")) ;
	this._scoreBg = new Bitmap( ResManager.getInstance().getBmdByName("score-control"));
	this._gameLayer = new GameLayer();
	this._scoreText  ;

	this.addChild(this._back);
	this.addChild(this._gameLayer);
	this.addChild(this._scoreBg);
	this.createScorePanel();
	this._score =0;
	var _self = this ;
	
	//==========方法=======================
	//全局事件处理
	this.scoreChangeHandler = function (e)
	{
		_self._score+= e.score;
		_self._scoreText.text="Score "+_self._score;
	};
	GlobalDispatcher.getInstance().addEventListener( ScoreEvent.SCORE_CHANGE , this.scoreChangeHandler );
	
	//延迟开始
	startGame = function()
	{
		_self._gameLayer.setStartFlag ( true) ;
	};
	setTimeout( startGame,500);
};
FLASH.extend(GameWorld , Sprite);
//GameWorld.prototype = new Sprite(); //继承自Sprite
//GameWorld.prototype.constructor = GameWorld ;

/**
 * 创建分数榜
 */
GameWorld.prototype.createScorePanel = function()
{
	this._scoreText = new TextField();
	this._scoreText.setX(80);
	this._scoreText.setY(23);
	this._scoreText.align = TextFieldAlign.LEFT ;
	this._scoreText.font="bold 25px Arial";
	this._scoreText.color = "#000000";
	this._scoreText.text="Score 0";
	this.addChild(this._scoreText);
};

/**
 * 重写父类的dispose方法
 */
GameWorld.prototype.dispose = function ()
{
	//将当前对象和子元素都执行dispose
	Sprite.prototype.dispose.call(this);
	GlobalDispatcher.getInstance().removeEventListener( ScoreEvent.SCORE_CHANGE , this.scoreChangeHandler );
	this._back = null ;
	this._scoreBg = null ;
	this._scoreText = null ;
};